﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KTXD.Data;
using KTXD.Entities;
using System.Data;

namespace UserKTXD.Controls
{
    public partial class ControlMenuTop : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                loadData();
        }
        private void loadData()
        {
            int TotalRows = 0;
            string WhereClause = "1=1 and TrangThai=1";
            TList<MenuTop> TList_Menu = DataRepository.MenuTopProvider.GetPaged(WhereClause, "IdOrder ASC", 0, 8, out TotalRows);
            drpMenuTop.DataSource = TList_Menu;
            drpMenuTop.DataBind();

        }
        protected void drpMenuTop_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
        {

            int TotalRows = 0;      
            Literal lit_Status = e.Item.FindControl("litStatus") as Literal;
            if(lit_Status.Text == "True")
            {
            Literal lit_Id = e.Item.FindControl("litId") as Literal;
            string id = lit_Id.Text.ToString();
            string WhereClause1 = "1=1 and TrangThai=1 and IdMenuTop="+id;
            Literal lit_Name = e.Item.FindControl("litContent") as Literal;
            lit_Name.Text += "<ul class=\"sub-menu dropdown-menu\">";
            TList<LoaiChuyenMuc> TList_LoaiChuyenMuc = DataRepository.LoaiChuyenMucProvider.GetPaged(WhereClause1, "ID", 0, 0, out TotalRows);
            if (TList_LoaiChuyenMuc.Count > 0)
            {
                
                for (int i = 0; i <= TList_LoaiChuyenMuc.Count-1;i++ )
                    //if (TList_LoaiChuyenMuc[0].LienKet.Length == 0 && TList_LoaiChuyenMuc[0].StatusLoaiMenu == false)
                    //{
                    //    TList<ChuyenMuc> TList_ChuyenMuc = DataRepository.ChuyenMucProvider.GetByIdLoaiChuyenMuc(TList_LoaiChuyenMuc[i].Id);
                    //    if (TList_ChuyenMuc.Count > 0)
                    //        lit_Name.Text += "<li><a href='" + ResolveUrl("../ChuyenMuc/" + TList_ChuyenMuc[0].IdLoaiChuyenMuc + "/" + GetTieuDe(TList_ChuyenMuc[0].TieuDe) + "_" + TList_ChuyenMuc[0].Id) + ".aspx'>" + TList_LoaiChuyenMuc[i].TenLoaiChuyenMuc + "</a></li>";
                    //}
                    //else
                    lit_Name.Text += "<li><a href='" + ResolveUrl("../LoaiChuyenMuc/" + GetTieuDe(TList_LoaiChuyenMuc[i].TenLoaiChuyenMuc) + "_" + TList_LoaiChuyenMuc[i].Id) + ".aspx'>" + TList_LoaiChuyenMuc[i].TenLoaiChuyenMuc + "</a></li>";
            }
            lit_Name.Text += "</ul>";
            }
        }

        //convert tiếng việt có dấu sang không dấu
        public string GetTieuDe(object Char)
        {
            string s = Char.ToString();
            return Common.ConvertToUnSign(s);
        }
    }
}